package com.cainaer.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cainaer.common.core.utils.StringUtils;
import com.cainaer.product.domain.ProductAttributeOption;
import com.cainaer.product.mapper.ProductAttributeOptionMapper;
import com.cainaer.product.service.IProductAttributeOptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统属性表 服务实现类
 * </p>
 *
 * @author Tina
 * @since 2020-09-11
 */
@Service
public class ProductAttributeOptionServiceImpl extends ServiceImpl<ProductAttributeOptionMapper, ProductAttributeOption> implements IProductAttributeOptionService {

    @Autowired
    private ProductAttributeOptionMapper productAttributeOptionMapper;

    /**
     * 新增系统属性
     *
     * @param productAttributeOption
     * @return
     */
    @Override
    public Integer insertProductAttributeOption(ProductAttributeOption productAttributeOption) {
        return productAttributeOptionMapper.insert(productAttributeOption);
    }

    /**
     * 编辑系统属性
     *
     * @param productAttributeOption
     * @return
     */
    @Override
    public Integer editProductAttributeOption(ProductAttributeOption productAttributeOption) {
        return productAttributeOptionMapper.updateById(productAttributeOption);
    }

    /**
     * 查询商品属性
     */
    @Override
    public List<ProductAttributeOption> selectProductAttributeOption(ProductAttributeOption productAttributeOption) {
        QueryWrapper queryWrapper = new QueryWrapper<>();

        //queryWrapper.eq()
        return productAttributeOptionMapper.selectList(queryWrapper);
    }

    /**
     * 查询商品默认属性
     *
     * @return
     */
    @Override
    public List<ProductAttributeOption> selectProductAttributeOrOption(Long productId) {
        if (StringUtils.isNotNull(productId)) {
            return productAttributeOptionMapper.selectProductAttributeOrOption(productId);
        }
        return productAttributeOptionMapper.selectProductAttributeOrOption(0L);
    }
}
